package com.CampaignManager.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DockLayoutPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public class MainPage extends Composite {

	private static MainPageUiBinder uiBinder = GWT.create(MainPageUiBinder.class);
	interface MainPageUiBinder extends UiBinder<Widget, MainPage> {
	}
	
	private CampaignManager mainForm = null;
	
	public MainPage(CampaignManager mainForm) {
		this.mainForm = mainForm;
		initWidget(uiBinder.createAndBindUi(this));
	}
	
	@UiField
	Label welcomeLabel;
	@UiField
	Anchor signoutAnchor;
	
	@UiField
	Button btnMap;
	@UiHandler("btnMap")
	void btnMapClick(ClickEvent event) {
		mainForm.showMap();
	}
	
	@UiField
	Button btnCharacterScreen;
	@UiHandler("btnCharacterScreen")
	void btnCharacterScreenClick(ClickEvent event) {
		
		mainForm.showCharacterScreen();
	}
	
	@UiField
	Button btnCurrentActivities;
	@UiHandler("btnCurrentActivities")
	void btnCurrentActivitiesClick(ClickEvent event) {
		
		mainForm.showActivities();
	}
	
	@UiField
	Button btnMyUnits;
	@UiHandler("btnMyUnits")
	void btnMyUnitsClick(ClickEvent event) {
		
		mainForm.showUnits();
	}	
	
	@UiField
	Button btnAddCity;
	@UiHandler("btnAddCity")
	void btnAddCityClick(ClickEvent event) {
		mainForm.isAddingCity = true;
	}
	
	@UiField
	Button btnPrimeData;
	@UiHandler("btnPrimeData")
	void btnPrimeDataClick(ClickEvent event) {
		mainForm.campaignService.PrimeData(new AsyncCallback<Void>() {
	    	public void onFailure(Throwable error) {
	    		mainForm.handleError(error);
	    	}

	    	public void onSuccess(Void result) {		
	    		Window.alert("priming done");
	    	}
    	});
	}
	
	@UiField
	HorizontalPanel northPanel;
	@UiField
	DockLayoutPanel centerPanel;
	
//	@UiField
//	Anchor signoutAnchor;
//	@UiField
//	FlexTable headerTable;
//	
//	@UiField
//	HorizontalPanel northPanel;
//	@UiField
//	DockLayoutPanel centerPanel;
//	
//	@UiField
//	FlexTable playerResourceTable;
//	
//	@UiField
//	FlexTable messageTable;
//	@UiField
//	TextArea newMessageText;
//	@UiField
//	ScrollPanel eastScroll;
//	
//	@UiField
//	FlexTable unitTable;
//	
//	@UiField
//	HorizontalPanel messageFromPanel;
//	@UiField
//	ListBox messageToText;
//	@UiField
//	TextBox messageFromText;
//	
//	@UiField
//	TextArea mapMarkerText;
//		
//	@UiField
//	Button addMessageButton;
//	@UiHandler("addMessageButton")
//	void addMessageClick(ClickEvent event) {
//		
//		if (newMessageText.getText().isEmpty()) {
//			Window.alert("Type something in the yellow box first");
//			return;
//		} else if (newMessageText.getText().length() >= 500) {
//			Window.alert("Messages have to be less than 500 characters. You're at " + newMessageText.getText().length());
//			return;
//		}			
//		
//		InboxMessageClient message = new InboxMessageClient();		
//		message.setTo(messageToText.getItemText(messageToText.getSelectedIndex()));
//		message.setFrom(messageFromText.getText());
//		message.setText(newMessageText.getText());
//		message.setCreateDate(new Date());
//		this.mainForm.AddMessage(message);
//		newMessageText.setText("");
//	}
//	
//	@UiField
//	Button addMarker;
//	@UiHandler("addMarker")
//	void addMarkerClick(ClickEvent event) {
//		
//		if (mapMarkerText.getText().isEmpty()) {
//			Window.alert("Type something in the yellow box first");
//			return;
//		} else if (mapMarkerText.getText().length() >= 500) {
//			Window.alert("Messages have to be less than 500 characters. You're at " + mapMarkerText.getText().length());
//			return;
//		}
//		
//		mainForm.AddMarker();		
//	}
//	
//	@UiField
//	Button useRuler;
//	@UiHandler("useRuler")
//	void useRulerClick(ClickEvent event) {
//		mainForm.UseRuler();
//	}
//	
//	@UiField
//	Button addRegion;
//	@UiHandler("addRegion")
//	void addRegionClick(ClickEvent event) {
//		mainForm.ShowAvailableJobsForm();
//	}
//	
//	@UiField
//	Button buyUnits;
//	@UiHandler("buyUnits")
//	void buyUnitsClick(ClickEvent event) {
//		mainForm.ShowBuyUnitsForm();
//	}
}
